package com.yurun.loginmodule.controller;

import com.yurun.commonapi.api.CommonResult;
import com.yurun.loginmodule.util.JWTUtil;
import com.yurun.orgparentmodule.service.ChildService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletRequest;
import java.math.BigInteger;

@Api(tags = "家长模块")
@RestController
@RequestMapping("/parentManage")
public class ParentController {

    @Autowired
    private ChildService childService;

    @ApiOperation(value = "根据id查询学生信息")
    //@RequiresPermissions("/allStudentInfo")
    @RequestMapping("/getChildInfoById")
    public CommonResult getChildInfoById(ServletRequest request) {
        // 获取token
        String token = WebUtils.toHttp(request).getHeader("Authorization").substring(6);
        // 获取学生id
        String studentId = JWTUtil.getUsername(token);
//        return childService.getChildInfoById(BigInteger.valueOf(Long.parseLong(studentId)));
        return childService.getChildInfoById(studentId);
    }

    @ApiOperation(value = "根据id查询学生个训课周训练记录表")
    @RequestMapping("/getChildAloneTrainWeek")
    public CommonResult getChildAloneTrainWeek(ServletRequest request,int pageNum, int pageSize) {
        // 获取token
        String token = WebUtils.toHttp(request).getHeader("Authorization").substring(6);
        // 获取学生id
        String studentId = JWTUtil.getUsername(token);
        return childService.getChildAloneTrainWeek(studentId,pageNum,pageSize);
    }
}
